package com.beiding.jsonanalyzer.analyze.query;

import com.beiding.jsonanalyzer.Key;
import com.beiding.jsonanalyzer.analyze.Undefind;
import com.beiding.jsonanalyzer.analyze.func.SelfObj;
import com.beiding.jsonanalyzer.analyze.query.queryfunc.*;

/**
 * 比较自身
 *
 * @author 丁常磊
 * @date 2022/6/27 10:42
 */

public interface SelfQueryGrammar extends ContextGenerate,ContextEmbellish, SelfObj {

    /**
     * 已定义
     *
     * @return
     */
    default ConnectGrammar defined() {

        //todo 用 not 加 undefined 来实现

        return null;

    }


    default QueryOperator typeof(Class type) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), type, new Typeof()))));
    }


    /**
     * 未定义
     *
     * @return
     */
    default QueryOperator undefined() {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), Undefind.i, new D_undefined()))));
    }


    default QueryOperator eq(Object rightValue) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), rightValue, new Eq()))));
    }

    default QueryOperator eqIgnoreCase(Object sub) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), sub, new EqIgnoreCase()))));
    }


    default QueryOperator contains(Object sub) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), sub, new Contains()))));
    }


    //匹配正则
    default QueryOperator matches(Object regex) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), regex, new Matches()))));
    }


    /**
     * 小于
     *
     * @param rightValue
     * @return
     */
    default QueryOperator lt(Object rightValue) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), rightValue, new Lt()))));

    }

    default QueryOperator le(Object rightValue) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), rightValue, new Le()))));
    }


    default QueryOperator gt(Object rightValue) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), rightValue, new Gt()))));
    }


    default QueryOperator ge(Object rightValue) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), rightValue, new Ge()))));
    }

    default QueryOperator in(Object collection) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), collection, new In()))));
    }


    /**
     * 可以自定义比较器
     *
     * @param queryCondition
     * @return
     */
    default QueryOperator custom(Comparator queryCondition) {
        return new QueryOperator(embellish(getQueryBuilder().addElement(new ValueConditionFactory(getSelf(), "%自定义比较器%", queryCondition))));
    }


    /**
     * 介于两个值之间
     *
     * @param a
     * @param b
     * @return
     */
    default QueryOperator between(Object a, Object b) {
        //todo 用 >= 和 <= 来实现
        return null;
    }

    @Override
    default Object getSelf() {
        return Key.parse("");
    }
}
